package com.share.dubbo.ssm.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.share.common.common.Page;
import com.share.dubbo.ssm.dao.mysql.AccessLogMapper;
import com.share.dubbo.ssm.manager.AccessLogManager;
import com.share.dubbo.ssm.model.AccessLogPageListReq;
import com.share.dubbo.ssm.model.mysql.AccessLog;
import com.share.dubbo.ssm.model.req.CountByDayResq;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 01401061 - 孙艳强
 * @date 2020/11/26 11:44
 */
@Service
public class AccessLogManagerImpl implements AccessLogManager {
    @Autowired
    private AccessLogMapper accessLogMapper;

    @Override
    public List<CountByDayResq> countByDay(String day) {
        List<CountByDayResq> countList = accessLogMapper.countByDay(day);
        return countList;
    }

    @Override
    public Page<AccessLog> pageListLocal(AccessLogPageListReq req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        QueryWrapper<AccessLog> queryWrapper = new QueryWrapper();
        if(StringUtils.isNoneEmpty(req.getUrl())){
            queryWrapper.like("url",req.getUrl());
        }
        if(StringUtils.isNoneEmpty(req.getHost())){
            queryWrapper.like("host",req.getHost());
        }
        List<AccessLog> list = accessLogMapper.selectList(queryWrapper);
        return new Page<>(list, new PageInfo<>(list).getTotal(), req);
    }
}
